<?php
    require_once('../code/global.php');
    require_once('/code/Admin.php');
    require_once('/code/Product.php');
    require_once('/code/Artist.php');
    require_once('/code/Category.php');
    $admin=new Admin();
    $admin->loginCheck(1);
    if(!isset($_GET['pid'])) {header('Location:photo.php');exit;}
    $pid=intval($_GET['pid']);
    $product=new Product();
    $p=$product->getProductByID($pid);
    if(empty($p)) {header('Location:photo.php');exit;}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>PhotoFromThe1st 后台管理系统</title>
        <link rel="stylesheet" href="/styles/admin.css" type="text/css" media="all">
        <script type="text/javascript" src="/script/jquery-1.6.1.min.js"></script>
        <script type="text/javascript" src="/script/script.js"></script>
        <script type="text/javascript">
            window.parent.scroll(0,0);
        </script>
    </head>
    <body>
        <?php
            if(isset($_GET['msg'])) echo '<div class="msgBox">'.$_GET['msg'].'</div>';
            else echo '<div class="msgBox">编辑照片信息 <a href="photo.php?cid='.$p['category_id'].'">返回</a></div>';
        ?>
        <table border="0" cellspacing="0" cellpadding="0" class="detailTable">
            <form name="editPhoto" action="exec.php" method="post">
                <input type="hidden" name="action" value="editPhoto">
                <input type="hidden" name="product_id" value="<?php echo $p['product_id']; ?>">
                <tr class="thumbTr"><td colspan="2"><img src="<?php echo $p['img_url']; ?>"/></td></tr>
                <tr class="seperator"><td colspan="2"></td></tr>
                <tr><td>Category:</td><td>
                        <select name="category_id">
                            <?php
                                $category=new Category();
                                $c=$category->getCategories(0);
                                $c_count=count($c);
                                $i=0;
                                while($i<$c_count){
                                    echo '<option value="'.$c[$i]['category_id'].'"'.($c[$i]['category_id']==$p['category_id']?' selected':'').'>'.$c[$i]['name'].'</option>';
                                    ++$i;
                                }
                            ?>
                        </select>
                    </td></tr>
                <tr><td>Subject:</td><td><input type="text" name="subject" maxlength="64" class="inputBox" value="<?php echo $p['subject']; ?>"></td></tr>
                <tr><td>Photographer:</td><td>
                        <select name="artist_id">
                            <option value="0"></option>
                            <?php
                                $artist=new Artist();
                                $a=$artist->getArtists(0);
                                $a_count=count($a);
                                $j=0;
                                while($j<$a_count){
                                    echo '<option value="'.$a[$j]['artist_id'].'"'.($a[$j]['artist_id']==$p['artist_id']?' selected':'').'>'.$a[$j]['name'].'</option>';
                                    ++$j;
                                }
                            ?>
                        </select>
                    </td></tr>
                <tr><td>Date:</td><td><input type="text" name="date" maxlength="64" class="inputBox" value="<?php echo $p['date']; ?>"></td></tr>
                <tr><td>Area:</td><td><input type="text" name="area" maxlength="64" class="inputBox" value="<?php echo $p['area']; ?>"></td></tr>
                <tr><td>Type:</td><td><input type="text" name="type" maxlength="64" class="inputBox" value="<?php echo $p['type']; ?>"></td></tr>
                <tr><td>Size:</td><td><input type="text" name="size" maxlength="64" class="inputBox" value="<?php echo $p['size']; ?>"></td></tr>
                <tr><td>Condition:</td><td><input type="text" name="condition" maxlength="64" class="inputBox" value="<?php echo $p['condition']; ?>"></td></tr>
                <tr><td>Code:</td><td><input type="text" name="code" maxlength="64" class="inputBox" value="<?php echo $p['code']; ?>"></td></tr>
                <tr><td>Price(￡):</td><td><input type="text" name="price" maxlength="64" class="inputBox" value="<?php echo $p['price']; ?>"></td></tr>
                <tr><td>Sold:</td><td><input name="is_sold" type="checkbox"<?php echo $p['is_sold']? 'checked':''; ?>></td></tr>
                <tr><td>Active:</td><td><input name="is_active" type="checkbox"<?php echo $p['is_active']? 'checked':''; ?>></td></tr>
                <tr><td>Created:</td><td><?php echo $p['create_time']?></td></tr>
                <tr><td>Modified:</td><td><?php echo $p['modify_time']?></td></tr>
                <tr class="btnTr header"><td colspan="2"><input class="btnLnk" type="submit" name="save" value="Save"><input class="btnLnk" type="reset" name="reset" value="Reset"><input  class="btnLnk" type="button" name="cancel" value="Cancel" onclick="location.href='photo.php?cid=<?php echo $p['category_id']; ?>'"></td></tr>
            </form>
            <form name="deletePhoto" action="exec.php" method="post"><input type="hidden" name="action" value="deletePhoto"><input type="hidden" name="product_id" value="<?php echo $p['product_id']; ?>"><input type="hidden" name="category_id" value="<?php echo $p['category_id']; ?>">
                <tr class="btnTr header"><td colspan="2"><input class="btnLnk btnDel" type="submit" name="delete" value="Delete"></td></tr>
            </form>
        </table>
    </body>
</html>